package com.boang.lambda;

import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/*
    @author:sa
    @date:2024/12/2 9:27
*/
public class LambdaDemo {
    public static void main(String[] args) {
//        m1();
//        m2();
//        m3();
//        m4();
//        m5();
        Comparator<Integer> comparator = new Comparator<>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(02);
            }
        };
        comparator = (o1, o2) -> o1.compareTo(o2);
        int i = comparator.compare(1, 2);
        System.out.println(i);
    }

    private static void m5() {
        Function<String, Integer> function = new Function<>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s);
            }
        };
        function = s -> Integer.parseInt(s);
        Integer apply = function.apply("123");
        System.out.println(apply);
    }

    private static void m4() {
        Supplier<String> supplier = new Supplier<>() {
            @Override
            public String get() {
                return "给你一个商品";
            }
        };
        supplier = () -> "给你一个商品";
        String string = supplier.get();
        System.out.println(string);
    }

    private static void m3() {
        Predicate<Integer> predicate = new Predicate<>() {
            @Override
            public boolean test(Integer integer) {
                return false;
            }
        };
        predicate = (a) -> a == 10;
        boolean bl = predicate.test(10);
        System.out.println(bl);
    }

    private static void m2() {
        MyConsumer myConsumer = new MyConsumer();
        myConsumer.accept("开始订饭");
        Consumer consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        consumer.accept("开始吃饭");
        consumer = s -> System.out.println(s);
        consumer.accept("吃完了");
    }

    private static void m1() {
        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName() + ":abc");
                    }
                }
        ).start();
        new Thread(() -> {
            System.out.println("abc");
        }).start();
        new Thread(() -> System.out.println("abc")).start();
    }
}